<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/website/common/base.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${webname }-忘记密码</title>
<%@ include file="/website/common/common.jsp"%>
<link href="${webctx }/css/login.css" rel="stylesheet" type="text/css" />
</head>

<body>
<%@ include file="/website/common/top.jsp"%>
<%@ include file="/website/common/head.jsp"%>

<div id="wrap-main">
	<div class="inner forget findpwdcon">
    	<div class="steps t-1"></div>
        <div class="forget-main">
        	<ul class="items">
				<li class="item">
                	<div class="item-title">账号：</div>
                	<div class="itemInp-ct">
                    	<div class="ipt norWidthIpt"><input name="loginname" type="text" class="inp" placeholder="请输入账号或手机号" style="height:36px;line-height:36px;"></div>
                    </div>
                    <div class="itemTip" id="logintip"></div>
                </li>
				<li class="item">
                	<div class="item-title">验证码：</div>
               	  	<div class="itemInp-ct">
                   		<div class="ipt" style="width:205px;"><input type="text" name="checkcode" class="inp" placeholder="输入验证码" style="height:36px;line-height:36px;"></div>
                      	<span  class="yzm-img" style="z-index: 99">
                       		<img id="checkcodeimg" onclick="getcheckcodeimg()" src="" width="110" height="38" alt="">
                          	<span class="yzm-tips">看不清？<a href="javascript:getcheckcodeimg()">换一张</a></span>
                      	</span>
                    </div>
                    <div class="itemTip" id="codetip"></div>
                    <div class="aui-clearfix"></div>
                </li>               
                <li class="item">
                	<div class="line8"></div><div class="line8"></div><div class="line8"></div><div class="line8"></div>
                	<div class="itemInp-ct pt-20"><a href="javascript:next1();" class="reg-btn">提交</a></div>
                </li>
			</ul>	
        </div>
    </div>
    <div class="inner forget findpwdcon hide">
    	<div class="steps t-2"></div>
        <div class="forget-main">
        	<ul class="items">
            	<li class="item">
                	<div class="itemInp-ct">短信已发送到<strong class="phTxt" id="usephone"></strong> 请输入短信验证码</div>
                </li>				
				<li class="item">
                	<div class="item-title">验证码：</div>
               	  	<div class="itemInp-ct">
                   		<div class="ipt"><input type="text" name="smscode" class="inp" placeholder="输入验证码" style="width:200px;height:36px;line-height:36px;"></div>
                      	<a href="javascript:tosendsms();" id="smsbtn" class="yzm-btn">重新发送</a>
                    </div> 
                     <div class="itemTip" id="itemTip_old"></div>                   
                </li>               
                <li class="item">
                	<div class="itemInp-ct pt-20"><a href="javascript:next2();" class="reg-btn">下一步</a></div>
                </li>
			</ul>
        </div>
    </div>
    <div class="inner forget findpwdcon hide">
    	<div class="steps t-3"></div>
        <div class="forget-main">
        	<ul class="items">            					
				<li class="item">
                	<div class="item-title">新密码：</div>
                	<div class="itemInp-ct">
                    	<div class="ipt norWidthIpt"><input name="newpwd" type="password" class="inp" placeholder="请输入新密码" style="height:36px;line-height:36px;"></div>
                    </div>
                     <div class="itemTip"></div>
                </li>
                <li class="item">
                	<div class="item-title">重复新密码：</div>
                	<div class="itemInp-ct">
                    	<div class="ipt norWidthIpt"><input name="newpwd2" type="password" class="inp" placeholder="请重复新的密码" style="height:36px;line-height:36px;"></div>
                    </div>
                    <div class="itemTip"></div>
                </li>
                <li style="padding:0px">
                	<div class="item-title"></div>
                	<div class="itemInp-ct" style="padding-bottom:8px">
                    	<div style="color:#FF6767;text-align:center;" id="tipold"></div>
                    </div>
                </li>               
                <li class="item">
                	<div class="itemInp-ct"><a href="javascript:ok();" class="reg-btn">确定</a></div>
                </li>
			</ul>	
        </div>
    </div>
    <div class="inner forget findpwdcon hide">
    	<div class="steps t-4"></div>
        <div class="forget-main">
        		<ul class="items">			
                <li class="item">
                	<div class="itemInp-ct">
                    	<div class="editTxt">
                            <img src="${webctx }/images/ok_y.png" />
                            <p class="pt-20">恭喜，密码已修改成功</p>
                        </div>
                    </div>
                </li>               
                <li class="item">
                	<div class="itemInp-ct pt-20"><a href="${ctx }/user/showlogin" class="reg-btn">去登录</a></div>
                </li>
			</ul>
        </div>
    </div>
</div>

<%@ include file="/website/common/foot.jsp"%>
<script type="text/javascript" src="${webctx}/js/sms.js"></script>
</body>
</html>
<script>
$(function(){
	getcheckcodeimg();
})
function getcheckcodeimg(){
	$("#checkcodeimg").attr("src",server+"/validateimg?d="+new Date().getTime());
}
var user;
function checkloginname(fun){
	$(".itemTip").text('');
	$w.httpRequest({
		url:apiroot+"/user/checkloginname",
		data:{"loginname":$("[name='loginname']").val()},
		ok:function(ret){
			user=ret.Data;
			fun();
		},fail:function(ret){
			if(ret.MsgCode=='2')$("#logintip").text("账号不存在");
			else if(ret.MsgCode=='3')$("#logintip").text("该手机绑定用户名，请输入用户名");
			else $("#logintip").text(ret.MsgDesc);
			return false;
		}
	})
}
function next1(){
	checkloginname(function(){
		$w.httpRequest({
			url:apiroot+"/user/checkimgcode",
			data:{"code":$("[name='checkcode']").val()},
			ok:function(ret){
				if(ret.Data){
					tosendsms();
					$("#usephone").text(user.phone);
					$(".findpwdcon").hide();
					$(".findpwdcon").eq(1).show();
				}else $("#codetip").text("验证码错误");
			}
		})
		
	})
}
function tosendsms(){
	sendsms(user.phone,'findpwd','smsbtn');
}
function next2(){
	$w.httpRequest({
		url:apiroot+"/user/checksmscode",
		data:{"mobile":user.phone,"smscode":$("[name='smscode']").val()},
		ok:function(ret){
			if(ret.Data=='true'){
				$(".findpwdcon").hide();
				$(".findpwdcon").eq(2).show();
			}else $("#itemTip_old").text('验证码错误');
		}
	})
}
var submiting=false;
function ok(){
	$(".itemTip").text('');
	if($("[name='newpwd']").val().length<6){
		$("[name='newpwd']").parent().parent().next().text("至少六位数密码");
		return;
	}
	if($("[name='newpwd2']").val()==''){
		$("[name='newpwd2']").parent().parent().next().text("请再一次输入新密码");
		return;
	}
	if($("[name='newpwd']").val()!=$("[name='newpwd2']").val()){
		$("[name='newpwd2']").parent().parent().next().text("两次密码不一致");
		return ;
	}
	if(!submiting){
		submiting=true;
		$w.httpRequest({
			url:apiroot+"/user/findpwd",
			data:{"userid":user.id,"phone":user.phone,"smscode":$("[name='smscode']").val(),"newpwd":$("[name='newpwd']").val()},
			ok:function(ret){
				$(".findpwdcon").hide();
				$(".findpwdcon").eq(3).show();
				try{
					sessionStorage.setItem("_curUrl_",ctx+"/user/home");
				}catch(e){}
			},fail:function(ret){
				$("#tipold").text(ret.MsgDesc);
				return false;
			},all:function(){submiting=false}
		})
	}
}
</script>